package com.michir.projects.jms.mocks;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.mockito.Mockito;

/**
 * {@link Session} Mocker: uses {@link Mockito}.
 * 
 * @author michir
 */
public class SessionMocker {

	/**
	 * use {@link #mock(ObjectMessage, MessageProducer, Boolean, Integer, Destination)}.
	 */
	private SessionMocker() {}

	/**
	 * {@link Session} factory method.
	 * @param producer 
	 * @param queue 
	 * @param transacted 
	 * @param acknowledgeMode 
	 * @return
	 * @throws JMSException 
	 */
	public static Session mock(ObjectMessage message, MessageProducer producer, Destination queue, Boolean transacted, Integer acknowledgeMode) throws JMSException {
		Session session = Mockito.mock(Session.class);
		Mockito.when(session.createObjectMessage()).thenReturn(message);
		Mockito.when(session.createProducer(queue)).thenReturn(producer);
		Mockito.doNothing().when(session).close();
		Mockito.when(session.getTransacted()).thenReturn(transacted);
		Mockito.when(session.getAcknowledgeMode()).thenReturn(acknowledgeMode);
		return session;
	}
}
